﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MyProFile_V2.Bll
{
    public class CurrentProjectFun
    {
        #region 数据库 常量获得
            #region 根据code 获得mssql字段类型  
        /// <summary>
        /// 根据code 获得类型 mssql
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string getDataType(int code)
        {
            string xtype = "";
            #region 获得类型
            switch (code)
            {
                case 34:
                    xtype = "Byte[]";
                    break;
                case 35:
                    xtype = "string";
                    break;
                case 36:
                    xtype = "string";
                    break;
                case 48:
                    xtype = "Byte";
                    break;
                case 52:
                    xtype = "Int16";
                    break;
                case 56:
                    xtype = "Int32";
                    break;
                case 58:
                    xtype = "DateTime";
                    break;
                case 59:
                    xtype = "Single";
                    break;
                case 60:
                    xtype = "Decimal";
                    break;
                case 61:
                    xtype = "DateTime";
                    break;
                case 62:
                    xtype = "float";
                    break;
                case 98:
                    xtype = "Object";
                    break;
                case 99:
                    xtype = "string";
                    break;
                case 104:
                    xtype = "Boolean";
                    break;
                case 106:
                    xtype = "Decimal";
                    break;
                case 108:
                    xtype = "Decimal";
                    break;
                case 122:
                    xtype = "Decimal";
                    break;
                case 127:
                    xtype = "Int64";
                    break;
                case 165:
                    xtype = "Byte[]";
                    break;
                case 167:
                    xtype = "string";
                    break;
                case 173:
                    xtype = "Byte[]";
                    break;
                case 175:
                    xtype = "Char";
                    break;
                case 189:
                    xtype = "DateTime";
                    break;
                case 231:
                    xtype = "string";
                    break;
                case 239:
                    xtype = "Char";
                    break;
                case 241:
                    xtype = "Char";
                    break;
            }
            #endregion
            return xtype;
        }
            #endregion

            #region 根据code 获得类型 默认值 mssql
        /// <summary>
        /// 根据code 获得类型 默认值 mssql
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string getDataDefValue(int code)
        {
            string xtype = "";
            #region 获得类型
            switch (code)
            {
                case 34:
                    xtype = "{Byte.Parse(\"\")}";
                    break;
                case 35:
                    xtype = "\"\"";
                    break;
                case 36:
                    xtype = " Guid.NewGuid().ToString()";
                    break;
                case 48:
                    xtype = "new Byte()";
                    break;
                case 52:
                    xtype = "0";
                    break;
                case 56:
                    xtype = "0";
                    break;
                case 58:
                    xtype = "DateTime.Now";
                    break;
                case 59:
                    xtype = "0";
                    break;
                case 60:
                    xtype = "0";
                    break;
                case 61:
                    xtype = "DateTime.Now";
                    break;
                case 62:
                    xtype = "0f";
                    break;
                case 98:
                    xtype = "new object()";
                    break;
                case 99:
                    xtype = "\"\"";
                    break;
                case 104:
                    xtype = "false";
                    break;
                case 106:
                    xtype = "0";
                    break;
                case 108:
                    xtype = "0";
                    break;
                case 122:
                    xtype = "0";
                    break;
                case 127:
                    xtype = "0";
                    break;
                case 165:
                    xtype = "{Byte.Parse(\"\")}";
                    break;
                case 167:
                    xtype = "\"\"";
                    break;
                case 173:
                    xtype = "{Byte.Parse(\"\")}";
                    break;
                case 175:
                    xtype = "new Char()";
                    break;
                case 189:
                    xtype = "DateTime.Now";
                    break;
                case 231:
                    xtype = "\"\"";
                    break;
                case 239:
                    xtype = "new Char()";
                    break;
                case 241:
                    xtype = "new Char()";
                    break;
            }
            #endregion
            return xtype;
        }
            #endregion

            #region 根据数据类型，获得参数第一位
            /// <summary>
            /// 根据数据类型，获得参数第一位
            /// </summary>
            /// <param name="dbType"></param>
            /// <returns></returns>
            public static string GetParamTypeByDbType(string dbType)
            {
                string value = "";
                switch (dbType)
                {
                    case "Access":
                        value = "OleDb";
                        break;
                    case "SQL":
                        value = "Sql";
                        break;
                    case "MySql":
                        value = "MySQL";
                        break;
                    case "Oracle":
                        value = "Oracle";
                        break;
                    case "Sqlite":
                        value = "SQLite";
                        break;
                }
                return value;
            }
            #endregion

            #region 不同数据库，不同命名空间
            /// <summary>
            /// 不同数据库，不同命名空间
            /// </summary>
            /// <param name="dbType"></param>
            /// <returns></returns>
            public static string GetNameSpaceByDbType(string dbType)
            {
                string value = "";
                switch (dbType)
                {
                    case "Access":
                        value = "System.Data.OleDb";
                        break;
                    case "SQL":
                        value = "System.Data.SqlClient";
                        break;
                    case "MySql":
                        value = "MySQLDriverCS";
                        break;
                    case "Oracle":
                        value = "System.Data.OracleClient";
                        break;
                    case "Sqlite":
                        value = "System.Data.SQLite";
                        break;
                }
                return value;
            }
            #endregion       
        #endregion

        private static string[] keyWordArray ={"添加","别名","ascending","descending","dynamic","from","get","global","group","into","join","let","orderby","partial","partial","remove","select","set","value","var","where","where","yield","abstract","as","base","bool","break","byte","case","catch","char","checked","class","const","continue","decimal","default","委托","do","double","else","enum","event","explicit","extern","false","finally","fixed","float","for","foreach","goto","if","implicit","in","in","int","interface","internal","为","lock","long","命名空间","new","null","object","operator","out","out","override","params","private","protected","public","readonly","ref","return","sbyte","sealed","short","sizeof","stackalloc","static","string","结构","switch","this","throw","true","try","typeof","uint","ulong","unchecked","unsafe","ushort","using","virtual","void","volatile","while" };
        /// <summary>
        /// 查是不是关键词
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool isCSKeyWord(string str)
        {
            bool flagz = false;
            foreach (string var in keyWordArray)
            {
                if (var.Equals(str))
                {
                    flagz = true;
                    break;
                }
            }
            return flagz;
        }
       

        

        
    }
}
